﻿
Public Structure lazier(Of T)
    Private Shared defaultValue As T = Nothing
    Private d As _do(Of T)

    Shared Sub New()
        defaultValue = [default](Of T)()
    End Sub

    Public Sub New(ByVal d As _do(Of T))
        Me.d = d
    End Sub

    Public Overrides Function ToString() As String
        Return Convert.ToString(+Me)
    End Function

    Public Shared Widening Operator CType(ByVal this As lazier(Of T)) As T
        Return +this
    End Operator

    Public Shared Widening Operator CType(ByVal this As _do(Of T)) As lazier(Of T)
        Return New lazier(Of T)(this)
    End Operator

    Public Shared Operator +(ByVal this As lazier(Of T)) As T
        If this.d Is Nothing Then
            Return defaultValue
        Else
            Return this.d()
        End If
    End Operator
End Structure
